#include <set>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <ctype.h>

using namespace std;

char expr[1000];
char *token;

int mis(int a,int b){
    return ((~b) & a);
}

int add(int a,int b){
    return (a|b);
}

int mul(int a,int b){
    return (a&b);
}

int __exp();

bool is_alpha(char c){
    return 'A'<=c && c<='Z';
}

int get_set(){

    int result = 0;
    while (is_alpha(*token)){
        result |=  (1<<(*token-'A')) ;
        token++;
    }
   // cout <<"::"<<result<<endl;
    return result;
}

int unary(){
   // cout << *token<<endl;
    char op = *token++;
    int result;
    switch(op){
        case '(':
            result = __exp();
            token++;
            break;
        case '{':
            result = get_set();
            token++;
            break;
    }

    return result;
}

int factor(){
    int result = unary();
  //  cout << result <<endl;
    if (*token == '*'){
        token++;
        result = mul(result , factor());
        //cout <<result<<endl;
    }
    return result;
}

int term(){
    int result = factor();
    int t;
    char op;
    while (*token=='+'|| *token=='-'){
        op = *token++;

        t = factor();
        switch(op){
            case '+':result = add(result, t);break;
            case '-':result = mis(result, t);break;
        }
    }
    return result;
}

int __exp(){
    return term();
}


int main(){
 //   freopen("2269.txt","r",stdin);
 //   freopen("2269.out","w",stdout);
    int result;

    while(scanf("%s",expr)!=EOF){
        token = expr;
        result = __exp();


        cout <<"{";
        for (char c = 'A' ; c<='Z';c++){
            if ((1<<(c-'A')) & result) cout << c;
        }
        cout << "}"<<endl;
    }
    return 0;
}
